<extend name="Center/base"/>
<block name="main_content">
    <link href="__CSS__/center.css" type="text/css" rel="stylesheet">
    <div class=" pd10 common_block_border">


        <div class="pd10">
            <h2 class="common_block_title">订单详情</h2>

            <div class="pd10">
                <table class="c_m_order_detail" style="width: 100%">
                    <tr style="background: #eee">
                        <td>订单编号：{$order.id}</td>
                        <td colspan="2">下单日期：{$order.create_time|friendlyDate}</td>
                        <td>订单状态：{$order.condition|getOrderCondition}</td>
                    </tr>
                    <tr>
                        <td>订单总价：￥{$order.total_cny|number_format=2}元
                        </td>
                        <td colspan="2">商品总数：{$order.total_count}</td>
                        <td>买家：<a href="{$order.user.space_url}" target="_blank" ucard="{$order.uid}">{$order.user.nickname}</a>
                            &&
                            卖家：<a href="{$order.s_user.space_url}" target="_blank" ucard="{$order.s_uid}">{$order.s_user.nickname}</a>
                        </td>
                    </tr>
                    <tr style="background: #eee">
                        <td colspan="4">商品列表</td>
                    </tr>
                    <volist name="order.items" id="vo">
                        <tr>

                            <td><img style="width: 32px;height: 32px" src="{$vo.h_pic|getThumbImageById=32,32}">
                                <a target="_blank"
                                   href="{:U('cat/Center/order',array('order_id'=>$vo['order_id']))}">{$vo.h_name}</a>
                            </td>
                            <td>成交单价：￥{$vo.h_price|number_format=2}元</td>
                            <td>成交数量：{$vo.count}</td>
                            <td>成交总价：￥
                                <php>echo number_format($vo['h_price']*$vo['count'],2);</php>
                                元
                            </td>
                        </tr>
                    </volist>
                    <tr style="background: #f8f8f8">
                        <td>合计：
                        </td>
                        <td></td>
                        <td>成交总数：{$order.total_count}</td>
                        <td>成交总价：￥{$order.total_cny|number_format=2}元&nbsp;&nbsp;
                        </td>
                    </tr>
                    <tr style="background: #f8f8f8">
                        <td>买家备注：
                            <if condition="$order['attach'] neq ''">
                                {$order.attach}
                                <else/>
                                无
                            </if>
                        </td>
                        <td>其他：
                        </td>

                        <td>调价：￥{$order.adj_cny}元</td>
                        <td>最终价：￥
                            <php>echo number_format($order['total_cny']+$order['adj_cny'],2);</php>
                            元&nbsp;&nbsp;
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="clearfix  f16px">
            <if condition="$self['lost'] lt 0">
                <div class="text-center" style="font-size: 32px;color: #808080">账户余额不足，无法支付该订单</div>
                <else/>
                <div class="col-xs-3 col-sm-offset-2">
                    账户余额
                    <br/>
                    {$self.currency|number_format=2}
                </div>
                <div class="col-xs-2">

                    <br/>
                    - {$order|getFinalPrice|number_format=2}
                    <br/>
                    <i class="glyphicon-arrow-right glyphicon" style="font-size: 36px"></i>
                </div>
                <div class="col-xs-3">
                    付款后余额
                    <br/>
                    {$self.lost|number_format=2}
                </div>

            </if>


        </div>
        <div class="pd10 clearfix">
            <form action="{:U('store/Center/payout',array('id'=>$order['id']))}" method="post">
                <if condition="$self['lost'] lt 0">
                    <btn class="btn btn-warning btn-lg pull-left" type="submit" disabled="disabled">付款</btn>
                    <else/>
                    <input class="btn btn-warning btn-lg pull-left" type="submit" value="付款">
                </if>

            </form>
            <button class="btn btn-default btn-lg pull-right" onclick="history.back()">返回</button>
        </div>

        <!--ping++和充值模块同时装的时候使用ping++-->
        <php>if(D('Module')->checkInstalled('Pingxx')){</php>

        <div class="pd10 clearfix">
            {:W('Pingxx/Pingxx/render',array('order_id'=>$order['id']))}
        </div>
        <php>}elseif(D('Module')->checkInstalled('Recharge')){</php>

        <div class="pd10 clearfix">
            {:W('Pay/pay',array('order_id'=>$order['id']))}
        </div>

        <php>}</php>
    </div>

    <style>
        .item_line:hover {
            background: #ebf6ff;
        }
        .item_line {
            border: dashed 1px #ccc;
            margin-top: -1px;
        }

    </style>
    <script>
        var total_cny = 0;
        $(function () {

            $('.comput_count').change(comput_event);
            $('.comput_count').each(comput_event);

        });


        comput_event = function comput() {
            if (isNaN($(this).val())) {
                $(this).val(1);
            } else {
                if ($(this).val() <= 0) {
                    $(this).val(1);
                }
            }
            var cny = parseFloat($(this).parent().parent().find('.comput_cny').attr('data'));
            var count = $(this).val();
            var good_id = $(this).attr('data');
            $.post(U('store/Center/_cart_set_item_count'), {good_id: good_id, count: count}, function (msg) {
            }, 'json');

            $(this).parent().parent().find('.comput_row_total').html('￥ <span class="comput_line_cny" data="' + (cny * count) + '">' + fmoney(cny * count, 2) + '</span>元 ');
            comput_all();
        };
        comput_total_cny = function () {
            total_cny += parseFloat($(this).attr('data'));
        };
        comput_all = function () {
            total_cny = 0;
            $('.comput_line_cny').each(comput_total_cny);
            $('.comput_total_cny').text(fmoney(total_cny, 2));
        };


        function fmoney(s, n) {
            n = n > 0 && n <= 20 ? n : 2;
            s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
            var l = s.split(".")[0].split("").reverse(),
                    r = s.split(".")[1];
            t = "";
            for (i = 0; i < l.length; i++) {
                t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
            }
            return t.split("").reverse().join("") + "." + r;
        }
    </script>
</block>

